package zouran.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zouran.entity.User;
import zouran.service.AdminService;

import java.util.List;

/**
 * @Author: zouran
 * @Description:
 * @Date: Created in 2022 2022/12/4 11:06
 **/
@CrossOrigin
@RestController
@RequestMapping(value = "/admin")
public class AdminController {
    private AdminService adminService;
    @Autowired
    public void setAdminService(AdminService adminService) {
        this.adminService = adminService;
    }

    /**
     * admin的特殊性，只提示账号或者密码错误,0代表错误,1代表正确,ajax中用res===1接收
     * @param phone 手机号码
     * @param password 密码
     * @return 0或1
     */
    @RequestMapping("/judge_admin")
    public int  judge_admin(@RequestParam("phone") String phone, @RequestParam("password") String password)
    {
        return adminService.judge_admin(phone,password);
    }

    /**
     * 管理员获得所有的用户信息
     * @return List集合
     */
    @RequestMapping("/getAllUser")
    public List<User> getAllUser()
    {
        return adminService.getAllUser();
    }

    /**
     * 管理员新增用户,true为成功
     * @param user 对象
     * @return boolean型，前端给能接收
     */
    @RequestMapping("/insert_user")
    public boolean insert_user(@RequestBody User user){
        return adminService.insert_user(user);
    }

    /**
     * 根据对象删除用户
     * @param user 对象
     * @return true/false
     */
    @RequestMapping("/delete_user")
    public boolean delete_user(@RequestBody User user){
        return adminService.delete_user(user);
    }
    /**
     * 更新用户信息,返回true
     * @param user 对象
     * @return true/false
     */
    @RequestMapping("/update_user")
    public boolean update_user(@RequestBody User user)
    {
        return  adminService.update_user(user);
    }

    /**
     * 根据手机号码查找用户信息
     * @param phone 用户手机号码
     * @return 返回一个类
     */
    @RequestMapping("/select_user")
    public List<User> select_user( @RequestParam("phone") String phone)
    {
        return adminService.select_user(phone);
    }
}
